#ifndef _LABELVIC_110817_INTERFACE_HELPER_H
#define _LABELVIC_110817_INTERFACE_HELPER_H



#define DECLARE_INTERFACE_HELPER(modname, classname)	\
class Dll##classname																			\
{																								\
public:																							\
    Dll##classname()																			\
    {																							\
    ++m_nRefCount;                                                                              \
    if (NULL==m_mod) m_mod = ::LoadLibraryA(#modname##".dll");									\
    if (NULL==_procCreate)                                                                      \
    if (NULL!=m_mod) _procCreate = (CREATE##classname)GetProcAddress(m_mod,"Create"#classname); \
        else _procCreate = NULL;																\
    }																							\
    ~Dll##classname()																			\
    {																							\
    if (--m_nRefCount<=0){                                                                      \
    if (m_mod) {::FreeLibrary(m_mod);m_mod=NULL;} m_nRefCount=0;}                               \
    }																							\
    I##classname *Create##classname(){if (_procCreate){return _procCreate();}				    \
        else{return NULL;}}	                                                                    \
    void Delete##classname(I##classname **p){if (*p) delete *p; *p=NULL;}                                   \
private:																						\
    static CREATE##classname		_procCreate;												\
    static HMODULE					m_mod;														\
    static int                      m_nRefCount;                                                \
};
#define IMPLETE_INTERFACE_HELPER(classname)\
    HMODULE Dll##classname::m_mod = NULL;   \
    CREATE##classname Dll##classname::_procCreate = NULL;\
    int Dll##classname::m_nRefCount = 0;


#define DLL_EXPORT_INTERFACE(classname, exporter)\
    extern "C" \
        ##exporter I##classname *Create##classname();\
    typedef I##classname *(*CREATE##classname)();    

#endif // _LABELVIC_110817_INTERFACE_HELPER_H